﻿@model OrderDetailsModel
@using SmartStore.Core.Domain.Orders;
@using SmartStore.Web.Models.Order;
@using SmartStore.Services.Localization;
@{
    if (!Model.PrintMode)
    {
        Layout = "~/Views/Shared/_ColumnsOne.cshtml";
    }
    else
    {
        Layout = "~/Views/Shared/_Print.cshtml";
    }
    //title
    Html.AddTitleParts(T("PageTitle.OrderDetails").Text);
}
@if (Model.PrintMode)
{
    <script type="text/javascript">
        $(document).ready(function () {
            window.print();
        });
    </script>
}
<div class="page order-details">
    @if (!Model.PrintMode)
    {
        <div class="clearfix">
            <div class="page-title pull-left">
                <div class="title">
                    <h1>@T("Order.OrderInformation")</h1>
                </div>
            </div>

            <div class="print-buttons pull-right" style="margin-top: 12px">
                <a href="@Url.RouteUrl("PrintOrderDetails", new { orderId = Model.Id })" target="_blank" class="btn print-order-button">
                    <i class="icon-print"></i>
                    @T("Order.Print")
                </a>
                @if (Model.DisplayPdfInvoice)
                {
                    <a href="@Url.RouteUrl("GetOrderPdfInvoice", new { orderId = Model.Id })" class="btn pdf-order-button">
                        @T("Order.GetPDFInvoice")
                    </a>
                }
            </div>
        </div>
    }

    <div class="page-body">
        @Html.Widget("orderdetails_page_top")
        <dl class="x-order-overview dl-horizontal">
            <dt>@T("Order.Order#"):</dt>
            <dd>@Model.OrderNumber</dd>

            <dt>@T("Order.OrderDate"):</dt>
            <dd>@Model.CreatedOn.ToString("D")</dd>

            <dt>@T("Order.OrderStatus"):</dt>
            <dd>@Model.OrderStatus</dd>

            <dt>@T("Order.OrderTotal"):</dt>
            <dd class="text-success"><strong>@Model.OrderTotal</strong></dd>
        </dl>
        @Html.Widget("orderdetails_page_overview")

        <div class="order-details-box well">
            <table class="order-details-table">
                <tbody>
                    <tr>
                        <td class="billinginfo">
                            <div class="title">
                                <strong>@T("Order.BillingAddress"):</strong>
                            </div>
                            <div class="name">
                                @Model.BillingAddress.FirstName @Model.BillingAddress.LastName
                            </div>
                            <div class="email">
                                @T("Order.Email"): @Model.BillingAddress.Email
                            </div>
                            @if (Model.BillingAddress.PhoneEnabled)
                            {
                                <div class="phone">
                                    @T("Order.Phone"): @Model.BillingAddress.PhoneNumber
                                </div>
                            }
                            @if (Model.BillingAddress.FaxEnabled)
                            {
                                <div class="fax">
                                    @T("Order.Fax"): @Model.BillingAddress.FaxNumber
                                </div>
                            }
                            @if (Model.BillingAddress.CompanyEnabled && !String.IsNullOrEmpty(Model.BillingAddress.Company))
                            {
                                <div class="company">
                                    @Model.BillingAddress.Company
                                </div>
                            }
                            @if (Model.BillingAddress.StreetAddressEnabled)
                            {
                                <div class="address1">
                                    @Model.BillingAddress.Address1
                                </div>
                            }
                            @if (Model.BillingAddress.StreetAddress2Enabled && !String.IsNullOrEmpty(Model.BillingAddress.Address2))
                            {
                                <div class="address2">
                                    @Model.BillingAddress.Address2
                                </div>
                            }
                            @if (Model.BillingAddress.CityEnabled ||
                            Model.BillingAddress.StateProvinceEnabled ||
                            Model.BillingAddress.ZipPostalCodeEnabled)
                            {
                                <div class="city-state-zip">
                                    @if (Model.BillingAddress.CityEnabled)
                                    {
                                        @Model.BillingAddress.City
                                    }
                                    @if (Model.BillingAddress.CityEnabled && (Model.BillingAddress.StateProvinceEnabled || Model.BillingAddress.ZipPostalCodeEnabled))
                                    {
                                        <text>,</text>
                                    }
                                    @if (Model.BillingAddress.StateProvinceEnabled)
                                    {
                                        @Model.BillingAddress.StateProvinceName
                                    }
                                    @if (Model.BillingAddress.ZipPostalCodeEnabled)
                                    {
                                        @Model.BillingAddress.ZipPostalCode
                                    }
                                </div>
                            }
                            @if (Model.BillingAddress.CountryEnabled && !String.IsNullOrEmpty(Model.BillingAddress.CountryName))
                            {
                                <div class="country">
                                    @Model.BillingAddress.CountryName
                                </div>
                            }
                            @if (!String.IsNullOrEmpty(Model.VatNumber))
                            {
                                <div class="vat">
                                    <div class="vat-label">
                                        <strong>@T("Order.VATNumber")</strong>
                                    </div>
                                    <div class="vat-value">
                                        @Model.VatNumber
                                    </div>
                                </div>
                            }
                            @if (!String.IsNullOrEmpty(Model.PaymentMethod))
                            {
                                <div class="payment-method">
                                    <div class="payment-method-label">
                                        <strong>@T("Order.PaymentMethod"):</strong>
                                    </div>
                                    <div class="payment-method-value">
                                        @Model.PaymentMethod
                                    </div>
                                </div>
                                if (!Model.PrintMode && Model.CanRePostProcessPayment)
                                {
                                @*Completing payment support (for redirection payment methods)*@
                                <div class="repost">
                                    @using (Html.BeginRouteForm("OrderDetails", FormMethod.Post))
                                    {
                                        <input type="submit" name="repost-payment" value="@T("Order.CompletePayment")" class="btn btn-primary re-order-button" />
                                        <p class="hint muted">
                                            @T("Order.CompletePayment.Hint")
                                        </p>
                                    }
                                </div>
                                }
                            }
                            @if (Model.DisplayPurchaseOrderNumber)
                            {
                                <div class="po">
                                    <div class="po-label">
                                        <strong>@T("Order.PurchaseOrderNumber")</strong>
                                    </div>
                                    <div class="po-value">
                                        @Model.PurchaseOrderNumber
                                    </div>
                                </div>
                            }
                        </td>
                        @if (Model.IsShippable)
                        {
                            <td class="shippinginfo">
                                <div class="title">
                                    <strong>
                                        @T("Order.ShippingAddress"):</strong>
                                </div>
                                <div class="name">
                                    @Model.ShippingAddress.FirstName @Model.ShippingAddress.LastName
                                </div>
                                <div class="email">
                                    @T("Order.Email"): @Model.ShippingAddress.Email
                                </div>
                                @if (Model.ShippingAddress.PhoneEnabled)
                                {
                                    <div class="phone">
                                        @T("Order.Phone"): @Model.ShippingAddress.PhoneNumber
                                    </div>
                                }
                                @if (Model.ShippingAddress.FaxEnabled)
                                {
                                    <div class="fax">
                                        @T("Order.Fax"): @Model.ShippingAddress.FaxNumber
                                    </div>
                                }
                                @if (Model.ShippingAddress.CompanyEnabled && !String.IsNullOrEmpty(Model.ShippingAddress.Company))
                                {
                                    <div class="company">
                                        @Model.ShippingAddress.Company
                                    </div>
                                }
                                @if (Model.ShippingAddress.StreetAddressEnabled)
                                {
                                    <div class="address1">
                                        @Model.ShippingAddress.Address1
                                    </div>
                                }
                                @if (Model.ShippingAddress.StreetAddress2Enabled && !String.IsNullOrEmpty(Model.ShippingAddress.Address2))
                                {
                                    <div class="address2">
                                        @Model.ShippingAddress.Address2
                                    </div>
                                }
                                @if (Model.ShippingAddress.CityEnabled ||
                            Model.ShippingAddress.StateProvinceEnabled ||
                            Model.ShippingAddress.ZipPostalCodeEnabled)
                                {
                                    <div class="city-state-zip">
                                        @if (Model.ShippingAddress.CityEnabled)
                                        {
                                            @Model.ShippingAddress.City
                                        }
                                        @if (Model.ShippingAddress.CityEnabled && (Model.ShippingAddress.StateProvinceEnabled || Model.ShippingAddress.ZipPostalCodeEnabled))
                                        {
                                            <text>,</text>
                                        }
                                        @if (Model.ShippingAddress.StateProvinceEnabled)
                                        {
                                            @Model.ShippingAddress.StateProvinceName
                                        }
                                        @if (Model.ShippingAddress.ZipPostalCodeEnabled)
                                        {
                                            @Model.ShippingAddress.ZipPostalCode
                                        }
                                    </div>
                                }
                                @if (Model.ShippingAddress.CountryEnabled && !String.IsNullOrEmpty(Model.ShippingAddress.CountryName))
                                {
                                    <div class="country">
                                        @Model.ShippingAddress.CountryName
                                    </div>
                                }
                                <div class="shipping-method">
                                    <div class="shipping-method-label">
                                        <strong>@T("Order.ShippingMethod"):</strong>
                                    </div>
                                    <div class="shipping-method-value">
                                        @Model.ShippingMethod
                                    </div>
                                </div>
                            </td>
                        }
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="clear">
        </div>
        @Html.Widget("orderdetails_page_beforeproducts")
        @if (Model.Items.Count > 0)
        {
            <div class="section-title">
                @T("Order.Product(s)")
            </div>

            <div class="products-box">
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            @if (Model.ShowSku)
                            {
                                <th class="a-center">
                                    @T("Order.Product(s).SKU")
                                </th>
                            }
                            <th>
                                @T("Order.Product(s).Name")
                            </th>
                            <th class="ar">
                                @T("Order.Product(s).Price")
                            </th>
                            <th class="ac">
                                @T("Order.Product(s).Quantity")
                            </th>
                            <th class="ar">
                                @T("Order.Product(s).Total")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Items)
                        {
                            <tr>
                                @if (Model.ShowSku)
                                {
                                    <td>
                                        @item.Sku
                                    </td>
                                }
                                <td>
                                    @if (!Model.PrintMode)
                                    {
                                        <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">@item.ProductName</a>
                                    }
                                    else
                                    {
                                        @item.ProductName
                                    }
                                    @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                    {
                                        <div class="attributes">
                                            @Html.Raw(item.AttributeInfo)
                                        </div>
                                    }
                                </td>
                                <td class="ar">
                                    @item.UnitPrice
                                </td>
                                <td class="ac">
                                    @item.Quantity
                                </td>
                                <td class="ar text-success">
                                    @item.SubTotal
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>

                @if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
                    <div class="checkout-attributes well well-small">
                        @Html.Raw(Model.CheckoutAttributeInfo)
                    </div>
                }

                @if (!Model.PrintMode)
                {
                    <div class="actions clearfix">
                        @if (Model.IsReOrderAllowed)
                        {
                            <a class="btn btn-primary re-order-button pull-right" href="@Url.RouteUrl("ReOrder", new { orderId = Model.Id })">
                                @T("Order.Reorder")
                            </a>
                        }
                        @if (Model.IsReturnRequestAllowed)
                        {
                            <a class="btn return-items-button pull-right" href="@Url.RouteUrl("ReturnRequest", new { orderId = Model.Id })">
                                @T("Order.ReturnItems")
                            </a>
                        }
                    </div>
                }
            </div>
        }
        @Html.Widget("orderdetails_page_afterproducts")
        <div class="row-fluid">
            <div class="total-info span8 offset16">
                <table class="cart-total table">
                    <tbody>
                        <tr>
                            <td class="cart-total-left">
                                <strong>@T("Order.SubTotal"):</strong>
                            </td>
                            <td class="cart-total-right">
                                <span class="nobr">
                                    @Model.OrderSubtotal
                                </span>
                            </td>
                        </tr>
                        @if (!string.IsNullOrEmpty(Model.OrderSubTotalDiscount))
                        {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @T("Order.SubTotalDiscount"):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @Model.OrderSubTotalDiscount
                                    </span>
                                </td>
                            </tr>
                        }
                        @if (Model.IsShippable)
                        {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @T("Order.Shipping"):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @Model.OrderShipping
                                    </span>
                                </td>
                            </tr>
                        }
                        @if (!string.IsNullOrEmpty(Model.PaymentMethodAdditionalFee))
                        {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @T("Order.PaymentMethodAdditionalFee"):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @Model.PaymentMethodAdditionalFee
                                    </span>
                                </td>
                            </tr>
                        }
                        @if (Model.DisplayTaxRates && Model.TaxRates.Count > 0)
                        {
                            foreach (var taxRate in Model.TaxRates)
                            {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @string.Format(T("Order.TaxRateLine").Text, taxRate.Rate):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @taxRate.Value
                                    </span>
                                </td>
                            </tr>
                            }
                        }
                        @if (Model.DisplayTax)
                        {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @T("Order.Tax"):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @Model.Tax
                                    </span>
                                </td>
                            </tr>
                        }
                        @if (!string.IsNullOrEmpty(Model.OrderTotalDiscount))
                        {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @T("Order.TotalDiscount"):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @Model.OrderTotalDiscount
                                    </span>
                                </td>
                            </tr>
                        }
                        @if (Model.GiftCards.Count > 0)
                        {
                            foreach (var gc in Model.GiftCards)
                            {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>
                                        @string.Format(T("Order.GiftCardInfo").Text, gc.CouponCode):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @gc.Amount
                                    </span>
                                </td>
                            </tr>
                            }
                        }
                        @if (Model.RedeemedRewardPoints > 0)
                        {
                            <tr>
                                <td class="cart-total-left">
                                    <strong>@string.Format(T("Order.RewardPoints").Text, Model.RedeemedRewardPoints):</strong>
                                </td>
                                <td class="cart-total-right">
                                    <span class="nobr">
                                        @Model.RedeemedRewardPointsAmount
                                    </span>
                                </td>
                            </tr>
                        }
                        <tr>
                            <td class="cart-total-left">
                                <strong>
                                    @T("Order.OrderTotal"):</strong>
                            </td>
                            <td class="cart-total-right">
                                <span class="nobr"><strong>
                                    @Model.OrderTotal</strong>
                                </span>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        @if (!Model.PrintMode)
        {
            if (Model.Shipments.Count > 0)
            {
            <div class="section-title">
                @T("Order.Shipments")
            </div>

            <div class="shipments-box">
                <table class="table">
                    <thead>
                        <tr>
                            <th>
                                @T("Order.Shipments.ID")
                            </th>
                            <th>
                                @T("Order.Shipments.TrackingNumber")
                            </th>
                            <th>
                                @T("Order.Shipments.ShippedDate")
                            </th>
                            <th>
                                @T("Order.Shipments.DeliveryDate")
                            </th>
                            <th>
                                @T("Order.Shipments.ViewDetails")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Shipments)
                        {
                            <tr>
                                <td>
                                    @item.Id.ToString()
                                </td>
                                <td>
                                    @item.TrackingNumber
                                </td>
                                <td>
                                    @if (item.ShippedDate.HasValue)
                                    {
                                        @item.ShippedDate.Value.ToString("D")
                                    }
                                    else
                                    {
                                        @T("Order.Shipments.ShippedDate.NotYet")
                                    }
                                </td>
                                <td>
                                    @if (item.DeliveryDate.HasValue)
                                    {
                                        @item.DeliveryDate.Value.ToString("D")
                                    }
                                    else
                                    {
                                        @T("Order.Shipments.DeliveryDate.NotYet")
                                    }
                                </td>
                                <td>
                                    <a href="@Url.RouteUrl("ShipmentDetails", new { shipmentId = item.Id })" title="@T("Order.Shipments.ViewDetails")">@T("Order.Shipments.ViewDetails")</a>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            }
        }

        @if (!Model.PrintMode)
        {
            if (Model.OrderNotes.Count > 0)
            {
            <div class="section-title">
                @T("Order.Notes")
            </div>

            <div class="ordernotes-box">
                <table class="table">
                    <thead>
                        <tr>
                            <th>
                                @T("Order.Notes.CreatedOn")
                            </th>
                            <th>
                                @T("Order.Notes.Note")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.OrderNotes)
                        {
                            <tr>
                                <td>
                                    @item.CreatedOn.ToString()
                                </td>
                                <td>
                                    @Html.Raw(item.Note)
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            }
        }
        @Html.Widget("orderdetails_page_bottom")
    </dl>
</div>
